package com.space.school.services.impl;

import com.space.school.dao.CategoryDao;
import com.space.school.dao.impl.CategoryDaoImpl;
import com.space.school.domain.Category;
import com.space.school.domain.User;
import com.space.school.services.CategoryService;
import com.space.school.utils.PageBean;

import java.util.List;
import java.util.Map;

public class CategoryServiceImpl implements CategoryService {
   CategoryDao categoryDao=new CategoryDaoImpl();
    @Override
    public PageBean<Category> search(int currentPage, int pageSize, Map<String, String[]> map) {
        int start=(currentPage-1)*pageSize;
        List<Category> list=categoryDao.search(start,pageSize,map);
        PageBean<Category> pb=new PageBean<Category>();
        pb.setList(list);
//        总数据数
        int count=categoryDao.count(map);
        pb.setTotalCount(count);
//        每页显示数据数
        pb.setRows(pageSize);
//        当前页
        pb.setCurrentPage(currentPage);
//        总页数
//        int Totalpage=(int)Math.ceil((double)count/pageSize);
        int totalPage =(count%pageSize==0 ? count/pageSize : count/pageSize+1);
        pb.setTotalPage(totalPage);
        return pb;
    }

    @Override
    public int delete(int id) {
        return categoryDao.delete(id);
    }

    @Override
    public void update(Category category) {
        categoryDao.update(category);
    }

    @Override
    public Category findById(int id) {
        return categoryDao.findById(id);
    }
}
